package com.zsrt.java.day20161230.wrl.t04;

public class Product {
	int pid;		//编码
	String pname;	//名称
	float  pvalue;	//价格
	String pmodel;	//型号
	String pclass;	//大类型
	
	//默认不带参数的构造器
	public Product() {
	}
	
	//带3个参数的构造器
	public Product(int pid,String pname, float pvalue) {
		this.pid	= pid;
		this.pname	= pname;
		this.pvalue	= pvalue;
	}
	//带所有参数的构造器
	public Product(int pid,String pname, float pvalue,String pmodel,String pclass) {
		this.pid	= pid;
		this.pname	= pname;
		this.pvalue	= pvalue;
		this.pclass	= pclass;
		this.pmodel = pmodel;
	}
	
	public String toSting(){
		return "商品 id: "+this.pid+"\t名称： "+this.pname+"   \t价格： "
				+this.pvalue+"  \t型号： "+this.pmodel+"  \t类别： "+this.pclass;
	}
	
	public static void main(String[] args) {
		Product p = new Product();
		System.out.println(p);
		System.out.println(p.toSting());
		
		//使用不带参数构造器创建对象
		Product p1 = new Product();
		System.out.println("p1: "+p1.toSting());
		p1.pid	 = 1001;
		p1.pname = "红牛";
		p1.pvalue = 6.5f;
		p1.pmodel = "P-1001";
		p1.pclass = "饮料";
		System.out.println("p1: "+p1.toSting());
		
		//使用带3个参数的构造器创建对象
		Product p2 = new Product(1002,"德芙巧克力",10.8f);
		System.out.println("P2: "+p2.toSting());
		
		//使用带所有参数的构造器
		Product p3 = new Product(1003, "娃哈哈", 3.5f, "p-1003", "饮料");
		System.out.println("p3: "+p3.toSting());
	}
}
